package com.atguigu.voddemo;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import org.junit.Test;

import java.util.List;

/**
 * @author gjl
 * @create 2021-04-10 10:29
 */
public class VodTest {
    String accessKeyId = "LTAI4GGBBL5y7aj3c9w2ab1Y";
    String accessKeySecret = "WqLbUikSceOLV0H1sAgSdKFNJFq1qE";

    //accessKeyId :LTAI4GGBBL5y7aj3c9w2ab1Y

    //accessKeySecret :WqLbUikSceOLV0H1sAgSdKFNJFq1qE

    /**
     *根据视频id获取地址
     * @throws ClientException
     */
    @Test
    public void testGetPlayInfo() throws ClientException {
        //1
        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);
        //2
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        GetPlayInfoResponse response = new GetPlayInfoResponse();
        //3
        request.setVideoId("bc88a9da616f426c90a98848962fe77b");
        //4
        response = client.getAcsResponse(request);
        //5
        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
        //播放地址
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
        }
    }

    /**
     * 根据id获取播放凭证
     */
    @Test
    public void testGetVideoPlayAuth() throws ClientException {
        //1
        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);
        //2
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        //3
        request.setVideoId("bc88a9da616f426c90a98848962fe77b");
        //4
        response = client.getAcsResponse(request);
        //播放凭证
        System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");

    }
}
